﻿//----------------------------------------------------------------------------------------------------
// The visual turn Counter is used to display number or turns to an event.
//----------------------------------------------------------------------------------------------------

package HG.Visual
{
	import flash.display.*;
	import flash.events.*;
	import flash.utils.Timer;
	
	import fl.transitions.Tween;
	import fl.transitions.easing.*;
	import fl.transitions.TweenEvent;
	
	import HG.GameService;
	import HG.Managers.GameRuleManager;
	import HG.Managers.LevelManager;
	import HG.Managers.TurnManager;
	import HG.Managers.AIManager;
	
	import HG.GameTypes.GameType_Rush;
	
	import HG.Events.GameEvent;
	
	public class VisualGameTypeInfo extends VisualObject
	{
		var m_gameRuleManager:GameRuleManager;
		var m_levelManager:LevelManager;
		var m_aiManager:AIManager;
		
		//----------------------------------------------------------------------------------------------------
		public function VisualGameTypeInfo()
		{
			m_gameRuleManager = GameService.GetInstance().GetGameRuleManager();
			m_levelManager = GameService.GetInstance().GetLevelManager();
			m_aiManager = GameService.GetInstance().GetAIManager();
			
			m_gameRuleManager.addEventListener(GameEvent.BEGIN, OnGameStart);
			m_gameRuleManager.addEventListener(GameEvent.GAMETYPE_UPDATE, OnGameTypeUpdate);
		}
	
		//----------------------------------------------------------------------------------------------------
		private function OnGameStart(evt:GameEvent)
		{
			SetVisible(true);
			
			switch(m_gameRuleManager.GetCurrentGameTypeID())
			{
				case GameRuleManager.GAMETYPE_NORMAL:
				{
					Setup_Normal();
				}break;
				
				case GameRuleManager.GAMETYPE_RUSH:
				{
					Setup_Rush();
				}break;
			}
		}
		
		//----------------------------------------------------------------------------------------------------
		private function OnGameTypeUpdate(evt:GameEvent)
		{
			switch(m_gameRuleManager.GetCurrentGameTypeID())
			{
				case GameRuleManager.GAMETYPE_NORMAL:
				{
					Update_Normal();
				}break;
				
				case GameRuleManager.GAMETYPE_RUSH:
				{
					Update_Rush();
				}break;
			}
		}
		
		//----------------------------------------------------------------------------------------------------
		private function Setup_Normal()
		{
			Disconnect.SetVisible(false);
			Sentry.SetVisible(false);
			Update_Normal();
		}
		
		//----------------------------------------------------------------------------------------------------
		private function Update_Normal()
		{
			var turns:Number = m_aiManager.GetTurnsToReachPlayer();
			
			if (turns <= 0)
			{
				Sentry.SetVisible(false);
			}
			else
			{
				Sentry.SetVisible(true);
				Sentry.SetValue(turns);
			}
		}
		
		//----------------------------------------------------------------------------------------------------
		private function Setup_Rush()
		{
			Disconnect.SetVisible(true);
			Update_Rush();
		}
		
		//----------------------------------------------------------------------------------------------------
		private function Update_Rush()
		{
			var rushGame:GameType_Rush = GameType_Rush(m_gameRuleManager.GetCurrentGameType());
			
			var newVal:Number = rushGame.GetTurnsToDisconnect();
			Disconnect.SetValue(newVal);
		}
		
		//----------------------------------------------------------------------------------------------------
	}
}